import { createApp } from 'vue'
import { createStore } from 'vuex'
import { setLocal, getLocal } from '@/utils/tool'
// 创建一个新的 store 实例
const store = createStore({
  state () {
    return {
      user: {},
      token: null
    }
  },
  mutations: {
    setUser (state,user) {
      setLocal('user', user)
      state.user = user
    },
    setToken (state,token) {
      setLocal('token', token)
      state.token = token
    }
  },
  getters:{
    getUser(state){
      return getLocal('user') || state.user
    },
    getToken(state){
      return getLocal('token') || state.token
    },
  }
})

export default store